# coding: utf-8
import socket

#创建一个TCP连接:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

#建立连接
s.connect(('52fhy.com',80))

#发送HTTP请求
s.send(b'GET / HTTP/1.1\r\nHost: 52fhy.com\r\nConnection: close\r\n\r\n')

#读取响应
buffer = []
while True:
    d = s.recv(1024)
    if d:
        buffer.append(d)
    else:
        break

data = b''.join(buffer)

#关闭连接
s.close()

#解析响应
header,body = data.split(b'\r\n\r\n',1)
print(header.decode('utf-8'))

with open('52fhy.html','wb') as f:
    f.write(body)


